<template>
    <div>
      <partner-loan v-if="show == '1'" :item="item" :tagItem="tagItem">
          <div  class="partner_apply" slot="loanBtn">
            <x-button style="background-color:rgb(47, 120, 236);color: #ffffff" @click.native="apply">立即申请</x-button>
        </div>
      </partner-loan>
      <partner-credit v-if="show == '3'" :item="item">
        <div class="partner_apply" slot="creditBtn">
            <x-button style="background-color:rgb(47, 120, 236);color: #ffffff;border-radius:1rem;" @click.native="apply">立即申请</x-button>
        </div>
      </partner-credit>
    </div>
</template>
<script>
import { XButton } from 'vux'
import PartnerLoan from '../comment/PartnerLoan'
import PartnerCredit from '../comment/PartnerCredit'
import api from '../api'
import utils from '../utils'
export default {
  data () {
    return {
      item: {},
      tagItem: {},
      show: '0'
    }
  },
  components: {
    PartnerLoan,
    PartnerCredit,
    XButton
  },
  created () {
    window.document.title = '产品详情'
    var params = {
      userId: this.$store.state.userID || '',
      partnerId: utils.getQueryString('partnerId')
    }
    api.creditloanDetail(params).then(res => {
      console.log(res)
      if (res.status === '200') {
        this.show = res.data.partnerType
        this.item = res.data
        this.tagItem = JSON.parse(this.item.productTag)
        this.sharecontent()
        utils.refreshShare(this.$wechat, this.$store)
      }
    })
  },
  methods: {
    apply () {
      window.location.href = '/customer/verify?shareParam=share&partnerId=' + utils.getQueryString('partnerId') + '&userId=' + utils.getQueryString('userId') + '&channel=' + utils.getQueryString('channel')
    },
    sharecontent () {
      var self = this
      var shareUrl, shareParams
      if (self.item.partnerId) {
        shareUrl = this.$store.state.Url + '/creditLogin/index'
        shareParams = '?shareParam=share&userId=' + utils.getQueryString('userId') + '&partnerId=' + utils.getQueryString('partnerId')
      } else {
        shareUrl = this.$store.state.Url + '/creditLogin/index'
        shareParams = '?shareParam=share&userId=' + utils.getQueryString('userId')
      }
      this.$store.commit('changeIndexConf', {
        shareTitle: self.item.shareTitle,
        shareDesc: self.item.shareDesc,
        shareImg: self.item.shareImageUrl,
        shareLink: shareUrl + shareParams
      })
    }
  }
}
</script>
